package cn.edu.zafu.bigdata.Wym;
import java.util.Scanner;

public class Wym_ScoreChecker {

    public static void main(String[] args){
        Scanner scanner=new Scanner(System.in);
        try {
            System.out.println("请输入分子：");
            int numerator = scanner.nextInt();
            System.out.println("请输入分母：");
            int denumerator = scanner.nextInt();

            Fraction a = new Fraction(numerator, denumerator);
            double scoreAsDouble = a.todouble();
            if (scoreAsDouble >= 0 && scoreAsDouble <= 100) {
                System.out.println("分数" + scoreAsDouble + "有效");
            } else {
                throw new InvalidScoreException("分数必须在0到100之间");
            }
        } catch (InvalidScoreException e){
            System.out.println("错误:"+e.getMessage());
        }finally {
            scanner.close();
        }
    }

}

class InvalidScoreException extends Exception{
    public InvalidScoreException(String a){
        super(a);
    }
}

class Fraction{
    private int numerator;
    private int denominator;

    public Fraction(int numerator, int denominator) throws InvalidScoreException{
        if (denominator==0){
            throw new InvalidScoreException("分母不能为0");
        }
        this.numerator=numerator;
        this.denominator=denominator;
    }

    public double todouble(){
        return (double) numerator/denominator;
    }
}